package org.kernely.scheduling.service;

import java.text.ParseException;
import java.util.Date;
import java.util.Map;
import java.util.Set;

import org.quartz.Job;
import org.quartz.JobDetail;

/**
 * Provides scheduling services, to manage cron-like tasks
 */
public interface KernelySchedulingService {

	/**
	 * Schedule a job using a cron pattern, without start and end time.
	 * This method register the job in KernelyScheduler (@see {@link KernelySchedulingService#registerJob(Class, String, String)})
	 * 
	 * @throws ParseException 
	 *
	 * @param jobClass	The job.
	 * @param description	The description of the job : what does it do ?
	 * @param cronExpression	The cron expression to determines when the job have to be executed.
	 */
	void scheduleJob(Class <? extends Job> jobClass, String description, String cronExpression) throws ParseException;

	/**
	 * Schedule a job using a cron pattern, and a specific start and/or end time.
	 * This method register the job in KernelyScheduler (@see {@link KernelySchedulingService#registerJob(Class, String, String)}).
	 * 
	 * @throws ParseException 
	 *
	 * @param jobClass	The job.
	 * @param description	The description of the job : what does it do ?
	 * @param cronExpression	The cron expression to determines when the job have to be executed.
	 * @param startTime	The first time the job have to be executed. Null permitted (the job will be executed as soon as possible).
	 * @param endTime	The last time the job have to be executed. Null permitted (the job will never end).
	 */
	void scheduleJob(Class <? extends Job> jobClass, String description, String cronExpression, Date startTime, Date endTime) throws ParseException;

	/**
	 * Schedule a job using a cron pattern.
	 * The job must have been previously registered with the {@link KernelySchedulingService#registerJob(Class, String)}.
	 * 
	 * @throws ParseException 
	 *
	 * @param jobClass	The job.
	 * @param cronExpression	The cron expression to determines when the job have to be executed.
	 */
	void scheduleRegisteredJob(Class <? extends Job> jobClass, String cronExpression) throws ParseException;

	/**
	 * Schedule a job using a cron pattern, with a specific start and/or end time.
	 * The job must have been previously registered with the {@link KernelySchedulingService#registerJob(Class, String)}.
	 * 
	 * @throws ParseException 
	 *
	 * @param jobClass	The job.
	 * @param cronExpression	The cron expression to determines when the job have to be executed.
	 * @param startTime	The first time the job have to be executed. Null permitted (the job will be executed as soon as possible).
	 * @param endTime	The last time the job have to be executed. Null permitted (the job will never end).
	 */
	void scheduleRegisteredJob(Class <? extends Job> jobClass, String cronExpression, Date startTime, Date endTime) throws ParseException;
	
	/**
	 * Register a job without executing it.
	 * Administrator can later activate it in the administration panel of the scheduling bundle.
	 * 
	 * @param jobClass
	 * @param description
	 */
	void registerJob(Class <? extends Job> jobClass, String description);
	
	/**
	 * Get all the registered jobs, scheduled or not.
	 * @return a set containing all job class and the associated JobDetail.
	 */
	Map<Class < ? extends Job >,JobDetail> getRegisteredJobs();
	
}
